import cv2

cap = cv2.VideoCapture(0)

width = 1920
height = 1080

cap.set(cv2.CAP_PROP_FRAME_WIDTH, width)  #设置宽度
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, height)  #设置长度

n = 0

while True:
    ret, frame = cap.read()

    if ret:
        cv2.imshow("Frame", frame)
        key = cv2.waitKey(1) & 0xFF

        # 检测键盘输入拍照
        if key == ord('s'):
            img = 'images/hand_pose_' + str(n) + '.jpg'
            cv2.imwrite(img, frame)

            print("[Saved Image at (%s)]" % img)
            n+=1
            
        if key == 27:
            break


cap.release()
cv2.destroyAllWindows()